<template>
	<view class="main">
		<image src="/static/logo.png" class="logo" mode="widthFix"></image>
		<view class="" style="margin-bottom: 100rpx;">
			学达鲸
		</view>
		<view class="btn">
			<button hover-class='none' open-type="getPhoneNumber" @getphonenumber="getUserPhone">手机号一键登录</button>
		</view>
	</view>
</template>

<script>
	import {
		get,
		post
	} from '../../utils/request';
	export default {
		data() {
			return {
				mobile: '',
				invite_mobile: ''
			}
		},
		onLoad() {},
		onReachBottom() {},
		onShow() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {
			uni.hideNavigationBarLoading();
			uni.stopPullDownRefresh();
		},

		methods: {
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			goPages(i) {
				uni.navigateTo({
					url: `${i}`
				})
			},
			getUserPhone(e) {
				const _this = this
				console.log(e)
				// uni.login({
				// 	timeout: 6000,
				// 	success: (res) => {
				get('/user/get_wx_mobile?code=' + e.detail.code).then(res => {
						if (res.code == 1) {
							this.mobile = res.data.mobile
							this.handleLogin()
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
				// 	},
				// })
			},
			handleLogin() {
				this.invite_mobile = uni.getStorageSync('invite_mobile')
				// const code = uni.getStorageSync('openid')
				var that = this
				wx.login({
					success(res) {
						if (res.code) {
							console.log(res.code, '微信code');
							uni.setStorageSync('openid', res.code)
							post('/user/wx_mobile_login', {
									code: res.code,
									mobile: that.mobile,
									invite_mobile: that.invite_mobile
								}).then(res => {
									if (res.code == 1) {
										uni.setStorageSync('userInfo', res.data.info)
										uni.setStorageSync('token', res.data.token)
										uni.switchTab({
											url: '/pages/index/index'
										})
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none'
										})
									}
								})
								.catch(err => {
									console.error('GET 请求失败:', err);
								});
						} else {
							console.log('登录失败！' + res.errMsg)
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	.main {
		font-family: PingFang SC;
		text-align: center;
	}

	.pop1 {
		padding: 61rpx 34rpx;
		border-radius: 26rpx;
		font-weight: 400;
		font-size: 34rpx;
		color: #727272;
		height: 700rpx;
		overflow-y: auto;

		.title {
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			margin-bottom: 45rpx;
			text-align: center;
		}
	}


	.logo {
		margin: 185rpx auto 20rpx;
		font-weight: 500;
		font-size: 36rpx;
		color: #79a88d;
		width: 168rpx;
		height: 168rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		// background: #FFFFFF;
		border-radius: 9rpx;
	}

	.btn button {
		line-height: 88rpx;
		background: #79a88d;
		border-radius: 50rpx;
		font-weight: 600;
		font-size: 30rpx;
		color: #FDFDFE;
		margin: 30rpx;
	}

	// .btn button {
	// 	line-height: 88rpx;
	// 	background: #FFFFFF;
	// 	border-radius: 50rpx;
	// 	font-weight: 500;
	// 	font-size: 30rpx;
	// 	color: #79a88d;
	// 	margin: 30rpx;
	// }

	.btn button::after {

		border: none;
	}

	.btn>view:nth-child(1) {
		float: left;
		margin-top: 10rpx;
	}

	.look {
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;
		text-align: center;
		position: fixed;
		bottom: 88rpx;
		left: 0;
		right: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		.radio {
			padding-top: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: #999;

			image {
				width: 25rpx;
				height: 25rpx;
				margin-right: 15rpx;
			}

			span {
				color: #4F5AD4;
			}
		}
	}

	.look span {
		color: #4F5AD4;
	}
</style>